
package application;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

import java.net.URL;
import java.util.ResourceBundle;

import db.DB_tools;
import javafx.event.ActionEvent;

import javafx.scene.control.RadioButton;

public class signUpPageController implements Initializable 
{
	@FXML
	private RadioButton male;
	@FXML
	private RadioButton female;
	@FXML
	private TextField Name;
	@FXML
	private TextField month;
	@FXML
	private TextField date;
	@FXML
	private TextField year;
	@FXML
	private TextField level;
	@FXML
	private TextField position;
	@FXML
	private TextField email;
	@FXML
	private TextField password;
	@FXML
	private Button Submit;
	@FXML
	private Button Cancel;
	@FXML
	private Button gotologin;
	@FXML
	private Label loginid;
	private Main application;
	
	  public void setApp(Main application){  
	        this.application = application;  
	    } 

	// Event Listener on Button[#Submit].onAction
	@FXML
	public void submit(ActionEvent event) 
	{
		// TODO Autogenerated
		if(male.isSelected())
		{
		int a;
		int Year=Integer.valueOf(year.getText());
		int Month=Integer.valueOf(month.getText());
		a=DB_tools.signup(Name.getText(), password.getText(), position.getText(), email.getText(),"m", level.getText());
		//a=DB_tools.getIDFromSignUp(Name.getText(), password.getText());
		DB_tools.addBirth(a,Name.getText(),Year,Month,date.getText());
		//application.userlogin();
		String id = String.valueOf(a);
		loginid.setText(id);
		}
		else
		{
			int a;
			int Year=Integer.valueOf(year.getText());
			int Month=Integer.valueOf(month.getText());
			a=DB_tools.signup(Name.getText(), password.getText(), position.getText(), email.getText(),"f", level.getText());
			//a=DB_tools.getIDFromSignUp(Name.getText(), password.getText());
			DB_tools.addBirth(a,Name.getText(),Year,Month,date.getText());
			//application.userlogin();
			String id = String.valueOf(a);
			loginid.setText(id);
		}
	}
	
	@FXML
	public void gotologin(ActionEvent event){
		application.userlogin();
	}
	// Event Listener on Button[#Cancel].onAction
	@FXML
	public void cancel(ActionEvent event) {
		Name.setText("");
		month.setText("");
		date.setText("");
		year.setText("");
		level.setText("");
		position.setText("");
		email.setText("");
		password.setText("");	
	}
	
	@Override
	public void initialize(URL location, ResourceBundle resources) 
	{
		// TODO Auto-generated method stub
		
	}
}